package com.share.controller.v1;


import com.share.common.result.ResponseResult;
import com.share.service.ISysMenuService;
import com.share.service.ISysUserService;
import com.share.service.IUserIdCardCurrentService;
import com.share.user.admin.dtos.RefreshTokenRequest;
import com.share.user.admin.dtos.SysUserDTO;
import com.share.user.admin.vo.UserIdCardCurrentVo;
import com.share.user.admin.vo.MenuItem;
import com.share.user.admin.vo.TokenResponse;
import com.share.user.admin.vo.UserInfoVo;
import com.share.util.common.ControllerUtils;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/user/v1")
public class AdminUserController {

    private final ISysUserService sysUserService;
    private final IUserIdCardCurrentService userIdCardCurrentService;
    private final ISysMenuService sysMenuService;
    
    @Autowired
    public AdminUserController(ISysUserService sysUserService, IUserIdCardCurrentService userIdCardCurrentService, ISysMenuService sysMenuService) {
        this.sysUserService = sysUserService;
        this.userIdCardCurrentService = userIdCardCurrentService;
        this.sysMenuService = sysMenuService;
    }

    /**
     * 登陆接口
     * @param sysUserDTO 用户信息
     * @return 返回操作码
     */
    @PostMapping("/login")
    public ResponseResult<String> login(@RequestBody SysUserDTO sysUserDTO){
        return ResponseResult.success("登陆成功");
    }


    /**
     * 刷新token
     * @return 返回操作码
     */
    @PostMapping("/refresh-token")
    public ResponseResult<TokenResponse> refresh(@Valid @RequestBody RefreshTokenRequest request){
        return ControllerUtils.messageHandler((() -> sysUserService.refToken(request)));
    }

    /**
     * 返回动态路由
     */
    @GetMapping("/get-async-routes")
    public ResponseResult<List<MenuItem>> getAsyncRoutes() {
        return ControllerUtils.messageHandler(sysMenuService::getRouter);
    }


    /**
     * 获取用户身份信息
     */
    @GetMapping("/WebInfo")
    public ResponseResult<UserInfoVo> getWebUserInfo() {
        return ControllerUtils.messageHandler(sysUserService::getUserInfo);
    }


    /**
     * 获取用户身份证信息
     */
    @GetMapping("/getIdCard")
    public ResponseResult<UserIdCardCurrentVo> getIdCard() {
        return ControllerUtils.messageHandler(userIdCardCurrentService::getIdCard);
    }


}
